﻿////////////////////////////////////////////////////////////////
///
/// File: Utils.cs
/// Author: Lucio Davide Spano
/// Last update: 27 July 2012
/// Description: Useful ground term delegates
/// To do: 
/// ------------------------------------------------------------
/// Copyright (c) 2012 Lucio Davide Spano 
///                     (lucio.davide.spano@isti.cnr.it)
/// 
/// The use and distribution terms for this software are 
/// contained in the file named license.txt, which can be found 
/// in the root of this distribution.
/// By using this software in any fashion, you are agreeing to 
/// be bound by the terms of this license.
///
/// You must not remove this notice, or any other, from this
/// software.
/// ------------------------------------------------------------
////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Kinect;

namespace BodyGestIT
{
    public class Utils
    {

        private static Utils singleton;

        public static Utils GetInstance()
        {
            if (singleton == null)
            {
                singleton = new Utils();
            }

            return singleton;
        }

        private Utils()
        {

        }

        double threshold = 0.001;
        public bool rightHandMove(BodyEventArgs args, BodyToken token)
        {
            
            Skeleton curr = args.Skeleton;
            Skeleton prev = token.GetSkeleton(curr.TrackingId, 0);

            if (prev == null)
            {
                return false;
            }
            double diffX = Math.Abs(
                prev.Joints[Microsoft.Kinect.JointType.HandRight].Position.X -
                 curr.Joints[Microsoft.Kinect.JointType.HandRight].Position.X);
            double diffY = Math.Abs(prev.Joints[Microsoft.Kinect.JointType.HandRight].Position.Y -
                 curr.Joints[Microsoft.Kinect.JointType.HandRight].Position.Y);

            return diffX > threshold || diffY > threshold;

          
        }
    }
}
